package com.example.spring.boot.api.user.createuser.impl;

import com.example.spring.boot.api.user.createuser.CreateUserRequest;
import com.example.spring.boot.api.user.createuser.CreateUserResponse;
import com.example.spring.boot.api.user.createuser.CreateUserService;
import com.example.spring.boot.business.user.CreateUserBusiness;
import com.example.spring.boot.business.user.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CreateUserServiceImpl implements CreateUserService {
    @Autowired
    CreateUserBusiness createUserBusiness;

    @Autowired
    CreateUserServiceConvert createUserServiceConvert = null;

    public CreateUserServiceConvert getCreateUserServiceConvert() {
        return createUserServiceConvert;
    }

    public void setCreateUserServiceConvert(CreateUserServiceConvert createUserServiceConvert) {
        this.createUserServiceConvert = createUserServiceConvert;
    }

    public CreateUserBusiness getCreateUserBusiness() {
        return createUserBusiness;
    }

    public void setCreateUserBusiness(CreateUserBusiness createUserBusiness) {
        this.createUserBusiness = createUserBusiness;
    }

    @RequestMapping("/user/create")
    @Override
    public CreateUserResponse createUser(CreateUserRequest createUserRequest) {
        UserModel userModel = createUserServiceConvert.toUserModel(createUserRequest);
        createUserBusiness.createUser(userModel);
        return createUserServiceConvert.toCreateUserResponse(userModel);
    }
}
